package be.javadevjunior.streeeloi.demineur.v1.business.generated.sound;

import be.javadevjunior.streeeloi.demineur.v1.business.beans.SoundBean;
import be.javadevjunior.streeeloi.demineur.v1.exception.PreconditionException;
import be.javadevjunior.streeeloi.demineur.v1.interfaces.ISoundLaucher;
import be.javadevjunior.streeeloi.demineur.v1.interfaces.ISoundManager;
import be.javadevjunior.streeeloi.demineur.v1.interfaces.ISoundPlayer;

public class SoundLauncher implements ISoundLaucher {

	private ISoundManager sounds = new SoundManager();
	private ISoundPlayer mediaplayer = new SoundPlayerJavaFXImpl();
	
	
	

	public SoundLauncher(ISoundManager sounds, ISoundPlayer mediaplayer) {
		super();
		if (sounds==null || mediaplayer==null) throw new PreconditionException();
		this.sounds = sounds;
		this.mediaplayer = mediaplayer;
	}

	@Override
	public void playThisSound(String nom) {
		if (nom != null) {
			SoundBean s = sounds.getSound(nom);
			if (s != null) {
				mediaplayer.play(s);

			}

		}

	}

	@Override
	public void playThisSoundIn(String nom, int milliSeconde) {

		//not implemented yet
		this.playThisSound(nom);
	}

	@Override
	public void stopThisSound(String nom) {
		if (nom != null) {
			SoundBean s = sounds.getSound(nom);
			if (s != null) {
				mediaplayer.stop(s);

			}

		}
	}

}
